package HUZ;


import java.util.Arrays;

//lambda表达式可以访问局部变量，但是不能修改局部变量
public class demo3 {
    public String name;

    public void setName(String name) {
        this.name = name;
    }

    public static void main(String[] args) throws InterruptedException {

//        Thread thread=new Thread(()->{
//            System.out.println("正在执行的线程:"+Thread.currentThread());
//        },"Theread11");
//        thread.start();


        int a=0;
        final int b=1;
        final int c=2;

        String A="A";
        String B="B";
        String C="C";

        int[] arr=new int[]{1,2,3};
        Animal animal=new Animal();
        animal.setAge(10);
        Animal[] arr1=new Animal[]{animal,null};

        Thread thread=new Thread(()->{
//            animal=new Animal();
            arr1[0]=new Animal();
            System.out.println("lambda使用局部变量"+a);
            System.out.println("lambda使用局部变量"+b);
            System.out.println("lambda使用局部变量"+c);

            System.out.printf("==========\n");
            System.out.println("lambda使用局部变量"+A);
            System.out.println("lambda使用局部变量"+B);
            System.out.println("lambda使用局部变量"+C);
            System.out.printf("==========\n");

            for (int i = 0; i < arr.length; i++) {
                arr[i]=444;
            }

        });
        thread.start();
        thread.join();

        for (int index:arr) {
            System.out.println(index);
        }
    }
}

class Animal{
    public int age;

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}
